/*
struct ListNode {
	int val;
	struct ListNode *next;
	ListNode(int x) :
			val(x), next(NULL) {
	}
};*/
class Solution {
public:
    ListNode* FindFirstCommonNode( ListNode* pHead1, ListNode* pHead2) {
        int len1=0;
		ListNode* node1=pHead1;
		while(node1)
		{
			len1++;
			node1=node1->next;
		}
		int len2=0;
		ListNode* node2=pHead2;
		while(node2)
		{
			len2++;
			node2=node2->next;
		}

		if(len1>len2)
		{
			int x=len1-len2;
			while(x--)
			{
				pHead1=pHead1->next;
			}
		}
		else {
			int x=len2-len1;
			while(x--)
			{
				pHead2=pHead2->next;
			}
		}

		while(pHead1!=pHead2)
		{
			pHead1=pHead1->next;
			pHead2=pHead2->next;
		}
		return pHead1;
    }
};
